import org.objectweb.asm.ClassAdapter;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.MethodVisitor;

import IL.ClassGenerator;
import ILTypes.ILClass;

public class MyClassAdapter extends ClassAdapter {

	public ILClass iCl;
	public ClassGenerator cg;
	
	public MyClassAdapter(ClassVisitor cv, String class_name) {
	          super(cv);
	          iCl = new ILClass();
	          cg = new ClassGenerator(iCl);
	}
	
	@Override
	public void visit(int version, int access, String name, String signature, String superName, String[] interfaces)
	{
		iCl.SetAccessCode(access);
		iCl.SetName(name);
		iCl.SetSignature(signature);
		iCl.SetSuperName(superName);
		iCl.SetInterfaces(interfaces);
		
		iCl.AddPrintInstructions("\n");
		iCl.AddPrintInstructions("Visiting class: " + name);
		
		iCl.AddPrintInstructions("Signature: " + signature);
		iCl.AddPrintInstructions("Access: " + access);
		iCl.AddPrintInstructions("SuperName: " + superName);

		iCl.AddPrintInstructions("Interfaces: ");
		
		for (String intface : interfaces) {
			iCl.AddPrintInstructions(intface);
		}
	}

	
	@Override
	  public MethodVisitor visitMethod(
	      int access, 
	      String methName, 
	      String methDesc,
	      String methSignGeneric, 
	      String[] exceptions) 
	  {
		MethodVisitor mv;
	    mv = cv.visitMethod(access, methName, methDesc, methSignGeneric, exceptions);
	    
	    if(methName=="main")
	    	iCl.entryClass = true;
	    
	    if (mv != null) {
		  mv = new MyMethodAdapter(mv, access, methName, methDesc, methSignGeneric, cg);
	    }
	    return mv;
	  }
	
	
	@Override
	public void visitEnd()
	{
		super.visitEnd();
	}
	
}
